<?php

class EventModule extends GigaModule
{
	var $name = 'Event';
	
	var $configuration = array(
		'model' => array(
			'type' => 'select',
			'empty' => '-Select-',
			'group' => 'add',
			'label' => 'Options',
			'options' => array(),
			'validate'=> VALID_NOT_EMPTY	
		),
		'limit'=>array(
			'type'=>"text",
			'group'=>"add",
			'default'=>5,
			'validate'=> VALID_NOT_EMPTY
		)
	);
	
	function __construct()
	{
		$this->configuration['model']['label'] = __("Options");
		$this->configuration['model']['options'] = array('populartw'=>__('Popular this week'), 'otherpopular'=>__('Other popular events'), 'recentevents' => __('Recently added'));
		$this->configuration['limit']['label'] = __("Number of records to be shown");
	}
	
	function render($params)
	{
		$viewObj = ClassRegistry::getObject('view');
		$limit = $params['limit'];
		if(!$limit || $limit >= 100)
		{
			$limit = 5;
		}
		$sideBarEvents = array();
		$EventModel = cri("Events.Event");
		if($params['model'] == "otherpopular") {
			$sideBarEvents = $EventModel->getOtherPopularEvents($limit);
		} else if($params['model'] == "populartw") {
			$sideBarEvents = $EventModel->getPopularThisWeek($limit);
		} else if($params['model'] == "recentevents") {
			$sideBarEvents = $EventModel->getRecentEvents($limit);
		}
		if(empty($sideBarEvents))
		{
			return false;
		}
		return $viewObj->element('events_sidebar', array('sideBarEvents' => $sideBarEvents,'limit' => $limit,'plugin'=>'events','sideCallerName'=>$params['model']));
	}
	
}
?>